Repository navigation
Write C, P and custom format strings the way decimal does [patch] - #141
Open
matt-edmondson wants to merge 2 commits into
Open
matt-edmondson wants to merge 2 commits into
matt-edmondson wants to merge 2 commits into
Conversation
The ktsu.PreciseNumber 2.6.11 bump made G, R, F, N and E work, but C, P and custom patterns such as "0.00" and "#,##0.0" still threw FormatException from ToString, TryFormat and string interpolation. Keep G, R, F, N and E on PreciseNumber, which writes them from the exact value. Write any other format through decimal when it holds the value exactly, and through double otherwise, so a format is refused only when decimal or double would refuse it too. TryFormat returns false when the destination is too small. Fixes #126 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW6Hi85XX4Q7wr44mWe
…ents, per SonarCloud Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW6Hi85XX4Q7wr44mWe
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



What was still broken
The ktsu.PreciseNumber 2.6.11 bump (which closed ktsu-dev/PreciseNumber#134) already made
G,R,F,NandEwork, as well asTryFormatand$"{x:F1}". These still threwFormatExceptionfromToString,TryFormatand interpolation:CandP"0.00"and"#,##0.0"PreciseNumber refuses these formats on purpose.
Change
G,R,F,NandE(with an optional precision) still go to PreciseNumber, which writes them from the exact value.decimalwhendecimalholds the value exactly, and throughdoubleotherwise, which is the fallback the issue suggests. A format is now refused only whendecimalordoublewould refuse it too.TryFormatreturnsfalsewhen the destination is too small, in both paths.Tests
SignificantNumberFormatTestschecks the results againstdecimal's output under InvariantCulture and a comma-decimal culture. That culture is built by hand because the CI container runs in globalization-invariant mode. The tests cover:ToStringandTryFormatacross F, N, E, C, P and custom patternsa destination that is too small
interpolation and
string.Formatvalues outside
decimal's range and precisionthe current culture when no provider is given
Without the library change, 26 of the 35 new cases fail.
With it, all 225 tests pass, with analyzers on.
Not in this PR
G<n>still differs fromdecimal:1234.5with"G3"gives1230, wheredecimalgives1.23E+03. The cause is in PreciseNumber, which never switchesG<n>to scientific notation, and ktsu-dev/PreciseNumber#172 tracks it. Bumping PreciseNumber after #172 lands will fix it here as well.Fixes #126
Generated by Claude Code